package example1;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.lang.id.NanoId;
import cn.hutool.core.util.IdUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.junit.Test;

import java.io.File;
import java.math.BigInteger;

public class TrimDIstZip {

    @Test
    public void t1() throws Exception {
        String filePath = "C:/Users/yangyang/Desktop/dist.zip";
        byte[] bytes = FileUtils.readFileToByteArray(FileUtils.getFile(filePath));

        String[] hexArray = HexUtil.byteToHexStringArray(bytes);

        HexUtil.writeHexArrToFile(hexArray, "C:/Users/yangyang/Desktop/viewHex.txt");
    }


    @Test
    public void t36() throws Exception {
        String filePath = "C:/Users/yangyang/Desktop/dist.zip";
        byte[] bytes = FileUtils.readFileToByteArray(FileUtils.getFile(filePath));
        String[] hexArray = HexUtil.byteToHexStringArray(bytes);

        HexUtil.writeHexArrToFile(hexArray, "C:/Users/yangyang/Desktop/viewHex36.txt");
    }

    @Test
    public void decode64() throws Exception {
        String filePath = "C:/Users/yangyang/Desktop/DC64.txt";
        String destName = "C:/Users/yangyang/Desktop/DC64.7z";
        String text = FileUtils.readFileToString(FileUtils.getFile(filePath), "UTF-8");
        Base64.decodeToFile(text, FileUtils.getFile(destName));
        //FileUtils.writeByteArrayToFile(FileUtils.getFile("C:/Users/yangyang/Desktop/DC64.7z"),decode);
    }

    @Test
    public void decode64Xlsx() throws Exception {
        String filePath = "C:/Users/yangyang/Desktop/平台开发计划_0612.zip.txt";
        String destName = "C:/Users/yangyang/Desktop/平台开发计划_0612.zip";
        String text = FileUtils.readFileToString(FileUtils.getFile(filePath), "UTF-8");
        Base64.decodeToFile(text, FileUtils.getFile(destName));
    }

    @Test
    public void testFileName() throws Exception {
        String saveFileName = "C:/Users/yangyang/Desktop/平台开发计划_0612.zip.txt";
        String baseName = FilenameUtils.getBaseName(saveFileName);
        File file = FileUtils.getFile(FileUtils.getFile(saveFileName).getParent(), baseName);
        System.out.println(file);
    }

    @Test
    public void testSecureGenerator() throws Exception {
        String uuid = IdUtil.randomUUID();
        String s = IdUtil.simpleUUID();
        String s1 = IdUtil.fastUUID();
        String s2 = IdUtil.nanoId();
        String s3 = IdUtil.nanoId(10);
        System.out.println();
    }

    @Test
    public  void testNanoIdExample  () {
        // 生成长度为10的NanoId
        String shortId1 = NanoId.randomNanoId().toUpperCase();
        System.out.println("Short ID (length 10): " + shortId1);

        // 生成长度为12的NanoId
        String shortId2 = NanoId.randomNanoId(12).toUpperCase();
        System.out.println("Short ID (length 12): " + shortId2);

        String shortId3 = NanoId.randomNanoId(10).toUpperCase();
        System.out.println("Short ID (length 10): " + shortId3);
    }

    @Test
    public void generateShortId() {
//        String shortId = ShortId.generate();
//        System.out.println("Short ID: " + shortId);

        String format = String.format("%ox", 1670784758205906944L);
        System.out.println(format);
    }

    @Test
    public void convertToShortId() {
        String numberString = "1670784758205906944";

        // 将数字字符串转换为 BigInteger
        BigInteger number = new BigInteger(numberString);

        // 将 BigInteger 转换为十六进制字符串
        String hexString = number.toString(36).toUpperCase();

        System.out.println("Hexadecimal ID: " + hexString);

        System.out.println(numberString);
        String encode = Base64.encode(numberString);
        System.out.println(encode);
    }
}
